﻿<phone:PhoneApplicationPage 
    x:Class="DDU.Curriculum.Views.FictionReadView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:viewmodel="clr-namespace:DDU.ViewModel;assembly=DDU.ViewModel"
    xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"
    xmlns:UX="clr-namespace:DDU.UX;assembly=DDU.UX"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
    shell:SystemTray.IsVisible="False" xmlns:Converters="clr-namespace:DDU.Converters;assembly=DDU.Converters">
    <phone:PhoneApplicationPage.Resources>
        <Converters:IndexToPaginateConverter x:Key="IndexToPaginateConverter" />
        <Converters:StreamToImageConverter x:Key="StreamToImageConverter" />
    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush Stretch="Fill" ImageSource="/Assets/back.png"/>
        </Grid.Background>
        <Grid.DataContext>
            <viewmodel:FictionReadViewModel/>
        </Grid.DataContext>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <controls:Pivot Title="{Binding Path=Fiction.Title}" ItemsSource="{Binding Fiction.PageCollection}" SelectedIndex="{Binding Path=CurrentIndex,Mode=TwoWay}">
            <controls:Pivot.HeaderTemplate>
                <DataTemplate>
                    <TextBlock/>
                </DataTemplate>
            </controls:Pivot.HeaderTemplate>
            <controls:Pivot.ItemTemplate>
                <DataTemplate>
                    <ScrollViewer>
                        <TextBlock Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding Content}" TextWrapping="Wrap" />
                    </ScrollViewer>
                </DataTemplate>
            </controls:Pivot.ItemTemplate>
        </controls:Pivot>

        <Grid Grid.Row="1" Margin="0,12">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <UX:UXPathButton HorizontalAlignment="Right" IconPath="{StaticResource PATH_ICON_PREVIOUS}" Command="{Binding Path=PrevCommand}" />
            <TextBlock Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource PhoneTextTitle3Style}" >
                <Run Text="{Binding Path=CurrentIndex, Converter={StaticResource IndexToPaginateConverter}}"/>
                <Run Text=" / "/>
                <Run Text="{Binding Fiction.TotalPages}"/>
            </TextBlock>
            <UX:UXPathButton HorizontalAlignment="Left" IconPath="{StaticResource PATH_ICON_NEXT}" Grid.Column="2" Command="{Binding Path=NextCommand}" />
        </Grid>
        
        <Button Grid.RowSpan="2" Command="{Binding Path=StartCommand}" Visibility="{Binding Path=CoverVisibility}">
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Image Grid.RowSpan="2" Stretch="Fill" Source="{Binding Path=Fiction.Cover, Converter={StaticResource StreamToImageConverter}}" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
    </Grid>
 
</phone:PhoneApplicationPage>
